<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<html>
		<script type="text/javascript" src="<%=contextPath%>/js/validator.js"></script> 
		<script type="text/javascript" language="javascript">  
			
			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				        {
				            text: '保存',
				            icon:"<%=contextPath%>/images/save.gif",
				            handler:toCheck,
				            hidden:<%=session.getAttribute("btn_save_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN"))? false:true%>
				        },'-',
				        {
				            text: '返回',
				            icon:"<%=contextPath%>/images/fanhui.png",
				            handler:function(){
				            	back();
				            }
				        }
			    	]
			    });
			});
		
			function toCheck(){

			  	if(!Validator.Validate(frmM,2)){
				  return false;
			  	}
			  	
			  	// 新建时
			  	if (document.frmM.elements["user.id"].value == 0) {

					// 要验证的编号
					var loginId = $("#loginId").val();
	
					$.ajax({
						type: "post",
						url : "<%=contextPath%>/user!check.do",
						dataType:'json',
						data: 'user.loginId=' + loginId,
						success: function(json,state){
	
							// 通过验证
							if (json.m == undefined) {
								$('#result').html("");
								// 提交
								comt();
							} else {
								$('#result').html("<nobr><font color='red'>" + json.m + "</font></nobr>");
							}
						},
						error:function(json) {
							alert("异步失败！");
						}
					});
					
					// 修改时
  				} else {
  				
  					comt();
  				}
		    }   

		    function openTree() {

		    	var win = window.open("<%=contextPath%>/jsp/sys/userOrganTree.jsp?flag=tree","Result_window","left=450,top=30,width=200,height=500,status=no,toolbar=no,autoscroll=yes,location=no,menubar=no,resizable=no",true);

		    }

		 </script>  
	</head>
	<body>
	<div id = "tbar" style="position:absolute;display:block left:0px; top:0px; width:100%; height:8%; z-index:1;"></div>
	<br>
	<div id="Layer" style="position:absolute;display:block left:0px; top:36px; width:100%; height:92%; z-index:1000; overflow:auto;">
		<center>
			<!-- 信息提示 -->
			<div result><font color="red">${info }</font></div>
		</center>
		<form id="frmM" name="frmM" method="POST" action="<%=contextPath%>/user!save.do">
			<s:hidden name="user.id" />
			<s:hidden name="searchBean.con1" />
			<s:hidden name="searchBean.con2" />
			<s:hidden name="searchBean.con3" />
			<table width="100%" id="infotab">
				<tr>
					<th   width="120" nowrap>
						<font color="red">*</font>&nbsp;用户名称：
					</th>
					<td>
						<input type="text" name="user.name" datatype="Require" maxlength="50" value="${user.name}" msg="用户名称必须输入。"/>
						
					</td>
					<th   width="120" >
						<font color="red">*</font>&nbsp;登录账号：
					</th>
					<td nowrap>
						<c:if test="${user.id==0}">
							<input type="text" datatype="Require" style="ime-mode:disabled;" name="user.loginId" maxlength="50" id="loginId" value="${user.loginId}" msg="登录账号必须输入。" />
							&nbsp;<div id="result"></div>
						</c:if>
						<c:if test="${user.id!=0}">
							&nbsp;<c:out value="${user.loginId}"/>
							<s:hidden name="user.loginId"/>
						</c:if>
					</td>
				</tr>
				<c:if test="${user.id==0}">
					<tr>
						<th   width="120" nowrap>
							登录密码重置：
						</th>
						<td>
							<input type="password" maxlength="25" datatype="Repeat" to="repass" name="user.password" msg="登陆密码与密码重置不一致。"/>
						</td>
						<th   width="120" nowrap>
							密码重置确认：
						</th>
						<td>
							<input type="password" name="repass" value=""/>
						</td>
					</tr>
				</c:if>
				<tr>
					<th   width="120" >
						<font color="red">*</font>&nbsp;机构：
					</th>
					<td nowrap>
						<s:hidden name="user.organ.id"/>
						<input type="text" readonly="true" datatype="Require" name="organName" value="${user.organ.organName}" msg="机构必须输入。" />
						<img src="<%=contextPath%>/images/editlink.gif" title="选择机构" onClick="javascript:openTree()" />
					</td>
					<th   width="120" nowrap>
						手机：
					</th>
					<td>
						<input type="text" datatype="Mobile" require="false" maxlength="11" name="user.mobile" value="${user.mobile}"  msg="手机格式输入不正确。" />
					</td>
				</tr>
				<tr>
					<th   width="120" nowrap>
						TEL：
					</th>
					<td>
						<input type="text" datatype="Phone" require="false" maxlength="50" name="user.tel" value="${user.tel}" msg="TEL格式输入不正确。" />
					</td>
					<th   width="120" nowrap>
						邮箱：
					</th>
					<td>
						<input type="text" datatype="Email" require="false" maxlength="50" name="user.email" value="${user.email}" msg="邮箱格式输入不正确。" />
					</td>
				</tr>
				<tr>
					<th   width="120" nowrap>
						是否是管理员：
					</th>
					<td>
						<s:radio name="user.isadmin"  list="#{'0':'否','1':'是'}"  listKey="key" listValue="value" />
					</td>
					<th   width="120" nowrap>
						排序号：
					</th>
					<td>
						<input type="text" datatype="Number" require="false" name="user.sortid" value="${user.sortid}" msg="排序号必须输入整数。" maxlength="2"/>
					</td>
				</tr>

			</table>
		</form>
		</div>
	</body>
</html>
<script language="javascript">
if (${user.id == "0"} ) {
		document.frmM.elements["organName"].value = parent.window.frames["treeForm"].chkOrganName;
		document.frmM.elements["user.organ.id"].value = parent.window.frames["treeForm"].chkOrganId;
	}
	 // 保存
     function comt(){
     	document.frmM.action = "<%=contextPath%>/user!save.do";
     	document.frmM.submit();
     }
     
     // 返回
     function back() {
     	document.frmM.action = "<%=contextPath%>/userList!getList.do";
		document.frmM.submit();
     }

	 // 查询
	 function cmt(){
		document.frmM.action = "<%=contextPath%>/userList!getList.do?page=1";
		document.frmM.submit();
	 }
</script>